% Note: 

function [FlowVec,CoefMat,UnitTrProbMat]=Distribution_TrProbMat(PP,SS,Pir,dE,Lag_PortfolioInfo,DistPolicy)

%% Step 1: from Lagfp_Lagzo to f_zo (Re-evaluation Effect)
Lagfp           =   SS.DistApp.fzo.State(:,1); 
LagID           =   SS.DistApp.fzo.State(:,2);
N_State         =   size(Lagfp,1);

LagID_FI        =   SS.FunApp.ExoState.State(LagID,2);

LagFI           =   PP.ExoState.Idio_FI.Node(LagID_FI);

Lag_PortfolioMat=reshape(Lag_PortfolioInfo,[4,2]);

Lag_DomShare_Pos=   Lag_PortfolioMat(1,1);
Lag_DomShare_Neg=   Lag_PortfolioMat(1,2);

DomShare        =   ones(N_State,1);
DomShare(LagFI & Lagfp>0)   =   Lag_DomShare_Pos;
DomShare(LagFI & Lagfp<0)   =   Lag_DomShare_Neg;
DomShare(LagFI & Lagfp==0)  =   PP.Fin_DomShare;

f               =   Lagfp.*(1+(1-DomShare)*dE*PP.Flag_dE)/(1+Pir);


%--------------------------------------------------------------------------
% Transition Matrix for each Dimension
%--------------------------------------------------------------------------
UnitTrMat       =   cell(2,1);

% to f
TempGrid_Fixed  =   SS.DistApp.TransFun.f.fromLogDiff(SS.DistApp.fzo.UnitNode{1});
TempGrid        =   SS.DistApp.TransFun.f.fromLogDiff(f);
UnitTrMat{1}    =   DistApp_Hist_TrMatApprox(TempGrid_Fixed,TempGrid);
% to zoID
UnitTrMat{2}    =   SS.FunApp.ExoState.TrMat(:,LagID);

%--------------------------------------------------------------------------
% Combined Transition Matrix
%--------------------------------------------------------------------------
TrProbMat_1     =   DistApp_Hist_TrMatAssemble(UnitTrMat,SS.DistApp.fzo.UnitNum(1:2));

%% Step 2: from f_zo to fp_zo (Consumption and Saving)
ID              =   SS.DistApp.fzo.State(:,2);
N_State         =   size(ID,1);
%--------------------------------------------------------------------------
% Transition Matrix for each Dimension
%--------------------------------------------------------------------------
UnitTrMat       =   cell(2,1);

% to fp
TempGrid_Fixed  =   SS.DistApp.TransFun.f.fromLogDiff(SS.DistApp.fzo.UnitNode{1});
TempGrid        =   SS.DistApp.TransFun.f.fromLogDiff(DistPolicy.V.fp);
UnitTrMat{1}    =   DistApp_Hist_TrMatApprox(TempGrid_Fixed,TempGrid);
% to zoID
UnitTrMat{2}    =   sparse(ID,(1:1:N_State)',ones(N_State,1),SS.DistApp.fzo.UnitNum(2),N_State);
%--------------------------------------------------------------------------
% Combined Transition Matrix
%--------------------------------------------------------------------------
TrProbMat_2     =   DistApp_Hist_TrMatAssemble(UnitTrMat,SS.DistApp.fzo.UnitNum(1:2));

%% Step 3: from Lagfp_LagID to fp_ID
CoefMat         =   (1-PP.XI)*TrProbMat_2*TrProbMat_1;
FlowVec         =   PP.XI*SS.DistApp.Entrant.QW;

UnitTrProbMat   =   struct('ReEval',TrProbMat_1,'ConSaving',TrProbMat_2);